import prompt from '@system.prompt';
import router from '@system.router';
import dataStorage from '@ohos.data.storage'
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility';
import http from '@ohos.net.http';
import request from '@ohos.request';

export default {
    data: {
        userid:null,
        searchparam:null,
        users:[],
    },
    TurnBack(){
        router.back();
    },
    searchinput(e){
        this.searchparam = e.text;
    },
    search(){
        let httpRequest= http.createHttp();
        httpRequest.request("http://101.35.82.76:9002/user/searchUsers?param=" +this.searchparam,
            {
                method: 'GET',
                readTimeout: 60000,
                connectTimeout: 60000
            },(err, data) => {
                if (!err) {
                    console.info('Result:' + data.result);
                    console.info('code:' + data.responseCode);
                    console.info('header:' + data.header);

                    var res = JSON.stringify(JSON.parse(data.result).data)
                    var users = JSON.stringify(JSON.parse(res).users)
                    this.users = JSON.parse(users)

                } else {
                    console.info('error:' + err.data);
                    prompt.showToast({
                        message: 'Send Error'+ JSON.stringify(err)
                    })
                }
            });
    },
    Follow(msg){
        console.info(`on touch start, data is: ${msg.target.dataSet.touserid}`);
        var touserid = `${msg.target.dataSet.touserid}`
        let httpRequest= http.createHttp();
        httpRequest.request("http://101.35.82.76:9002/follow/addFollow?userid=" +this.userid+'&touserid='+touserid,
            {
                method: 'GET',
                readTimeout: 60000,
                connectTimeout: 60000
            },(err, data) => {
                if (!err) {
                    console.info('Result:' + data.result);
                    console.info('code:' + data.responseCode);
                    console.info('header:' + data.header);

                } else {
                    console.info('error:' + err.data);
                    prompt.showToast({
                        message: 'Send Error'+ JSON.stringify(err)
                    })
                }
            });
    },
    ownmainpage(msg){
        var touserid = `${msg.target.dataSet.touserid}`
        var toheadshot = `${msg.target.dataSet.toheadshot}`
        var tousername = `${msg.target.dataSet.tousername}`
        router.push({
            uri: "pages/ownmainpage/ownmainpage",
            params: {
                touserid:touserid,
                userid:this.userid,
                tousername:tousername,
                toheadshot:toheadshot,
            }
        });
    },
}
